package com.opc.demo.controller;

import com.alibaba.fastjson.JSON;
import com.opc.demo.util.OPCHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
public class OpcController {

    @Autowired
    private OPCHelper opcHelper;


    @RequestMapping("/")
    public String health() {
        return "Hello World opc";
    }

    @RequestMapping(value = "/readTags", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public String readTags(@RequestParam List<String> tags) {
        Map<String, Object> map = opcHelper.readTags(tags);
        if (map != null && map.size() > 0) {
            return JSON.toJSONString(map);
        } else {
            return "read fail!";
        }
    }

    @RequestMapping(value="/showServerList", method = RequestMethod.GET)
    public String showServerList() {
        List<Map<String, Object>> list = opcHelper.showAllOPCServer();
        return JSON.toJSONString(list);
    }

}
